package io.renren.modules.basic.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.QueryChainWrapper;
import io.renren.modules.basic.entity.MtCcWarehousRankEntity;
import io.renren.modules.basic.service.MtCcWarehousRankService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-10-14 10:50:42
 */
@RestController
@RequestMapping("generator/mtccwarehousrank")
public class MtCcWarehousRankController {
    @Autowired
    private MtCcWarehousRankService mtCcWarehousRankService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:mtccwarehousrank:list")
    public R list(@RequestParam Map<String, Object> params){
        List<MtCcWarehousRankEntity> list = mtCcWarehousRankService.queryPage(params);

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:mtccwarehousrank:info")
    public R info(@PathVariable("id") Integer id){
		MtCcWarehousRankEntity mtCcWarehousRank = mtCcWarehousRankService.getById(id);

        return R.ok().put("mtCcWarehousRank", mtCcWarehousRank);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:mtccwarehousrank:save")
    public R save(@RequestBody MtCcWarehousRankEntity mtCcWarehousRank){
		mtCcWarehousRankService.save(mtCcWarehousRank);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:mtccwarehousrank:update")
    public R update(@RequestBody MtCcWarehousRankEntity mtCcWarehousRank){
		mtCcWarehousRankService.updateById(mtCcWarehousRank);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:mtccwarehousrank:delete")
    public R delete(@RequestBody Integer[] ids){
		mtCcWarehousRankService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 修改库位命名
     * 导入数据时使用
     */
    /*@ApiOperation(value = "修改库位命名",notes="修改库位命名")
    @RequestMapping("/xiugai")
    public R xiugai(){
        List<MtCcWarehousRankEntity> list = mtCcWarehousRankService
                .list(new QueryWrapper<MtCcWarehousRankEntity>()
                        .inSql("id","select id from mt_cc_warehous_rank where id between 281 and 320"));
        System.out.println(list.size());
        int n=1;
        int m=1;
        for (MtCcWarehousRankEntity mtCcWarehousRankEntity:list
             ) {
            mtCcWarehousRankEntity.setColumnCode("C01");

            if (mtCcWarehousRankEntity.getId()%2==1){//奇数
                mtCcWarehousRankEntity.setAnotherName("第8层第1列"+n+"号位");

                mtCcWarehousRankEntity.setRowCode("R08");
                mtCcWarehousRankEntity.setDirection("R");
                mtCcWarehousRankEntity.setRegionName("普通库位");
                mtCcWarehousRankEntity.setSequence(n);
                String sn="";
                if (n<10){
                    sn="0"+n;
                    mtCcWarehousRankEntity.setPositionCode("0101"+mtCcWarehousRankEntity.getColumnCode()+mtCcWarehousRankEntity.getRowCode()+sn);
                }else {
                    mtCcWarehousRankEntity.setPositionCode("0101"+mtCcWarehousRankEntity.getColumnCode()+mtCcWarehousRankEntity.getRowCode()+n);
                }
                n++;
            }else {
                mtCcWarehousRankEntity.setAnotherName("第8层第2列"+m+"号位");

                mtCcWarehousRankEntity.setRowCode("R08");
                mtCcWarehousRankEntity.setDirection("L");
                mtCcWarehousRankEntity.setRegionName("普通库位");
                mtCcWarehousRankEntity.setSequence(m);
                String sm="";
                if (m<10){
                    sm="0"+m;
                    mtCcWarehousRankEntity.setPositionCode("0101"+mtCcWarehousRankEntity.getColumnCode()+mtCcWarehousRankEntity.getRowCode()+sm);
                }else {
                    mtCcWarehousRankEntity.setPositionCode("0101"+mtCcWarehousRankEntity.getColumnCode()+mtCcWarehousRankEntity.getRowCode()+m);
                }
                m++;
            }

            mtCcWarehousRankService.updateById(mtCcWarehousRankEntity);
        }
        return R.ok();
    }*/
}
